import java.util.Scanner;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Bank {
    public static void main(String[] args) {
        // 管理员后台
        Scanner per = new Scanner(System.in);
        System.out.println("管理员请输入账户集合人数");
        int p = per.nextInt();
        Account[] customer = new Account[p];
        System.out.println("管理员请输入用户管理人数");
        int q = per.nextInt();
        if (p >= q) {
            System.out.println("请设定当期利率");
            double r = per.nextDouble();

            for (int i = 0; i < q; i++) {

                // 账户信息初始化
                customer[i] = new Account(123456, 100, 0, "用户", 0, 0, 0);
                customer[i].setRate(r);
                // 登录系统
                Menu.showLoadinMenu();

                // 账户信息检验入口
                Scanner data = new Scanner(System.in);
                System.out.println("请输入账号");
                int _id = data.nextInt();
                boolean t1 = customer[i].testID(_id);
                System.out.println("请输入密码");
                int load = data.nextInt();
                boolean t2 = customer[i].testSecretcode(load);
                if (t1 && t2 == true) {

                    // 显示登陆界面

                    Scanner num = new Scanner(System.in);
                    int service = 0;
                    int service1 = 0;
                    int service2 = 0;
                    Menu.showFuntionMenu();
                    service = data.nextInt();
                    switch (service) {
                        // 用户信息修改业务（名字 密码 个人信息绑定
                        case 1:
                            do {
                                System.out.println("\t" + "1. 信息绑定" + "\t" + "2. 密码修改" + "\t");
                                service1 = num.nextInt();
                                switch (service1) {
                                    case 1:
                                        // 信息绑定
                                        customer[i].getID();
                                        Scanner input = new Scanner(System.in);
                                        System.out.println("请输入用户名");
                                        String name = input.nextLine();
                                        customer[i].setName(name);
                                        System.out.println("请绑定用户手机号");
                                        int phonenumber = num.nextInt();
                                        customer[i].setPhone(phonenumber);
                                        break;
                                    case 2:
                                        // 密码修改业务
                                        customer[i].testNewcode();
                                        break;
                                }
                            } while (service1 != 0);
                            break;
                        // 查询余额业务
                        case 2:
                            System.out.println("余额： " + customer[i].getBalance());
                            break;
                        // 存取款业务
                        case 3:
                            do {
                                System.out.println("\t" + "1. 存款业务" + "\t" + "2. 取款业务");
                                service2 = num.nextInt();
                                switch (service2) {
                                    case 1:
                                        // 存款业务
                                        System.out.println("请输入存款金额");
                                        int de = num.nextInt();
                                        customer[i].setDeposit(de);
                                        break;
                                    case 2:
                                        // 取款业务
                                        System.out.println("请输入取款金额");
                                        int wi = num.nextInt();
                                        customer[i].setWithdraw(wi);
                                        break;
                                }
                            } while (service2 != 0);
                            break;
                        case 4:
                            // 理财方案选择业务
                            customer[i].getRate();
                            break;
                        case 5:
                            // 表单打印
                            // 表单打印
                            System.out.println(
                                    "_____________________________________________________________________________________________________");
                            System.out.println("\t" + "用户账户" + "\t" + "用户姓名" + "\t" + "存款金额" + "\t" + "取款金额" + "\t"
                                    + "当期利率" + "\t" + "余额");
                            System.out.println("\t" + customer[i].getID() + "\t" + customer[i].getName() + "\t"
                                    + customer[i].getDeposit() + "\t" + customer[i].getWithdraw() + "\t"
                                    + customer[i].gettheRate() + "\t" + customer[i].getBalance());
                            System.out.println();
                            // System.out.print("\t" + customer[i].getID());
                            // System.out.print("\t" + " " + customer[i].getName());
                            // System.out.print("\t" + " " + customer[i].getDeposit());
                            // System.out.print("\t" + " " + customer[i].getWithdraw());
                            // System.out.print("\t" + " " + customer[i].gettheRate());
                            // System.out.print("\t" + " " + customer[i].getBalance());
                            // System.out.println();
                            break;
                    }
                }
                customer[i].changeID();
            }
        } else {
            System.out.println("账号信息有误！");

        }
    }
}
